<script setup>
import OImage from "../setting/Images.vue";
import AlphaColor from "../setting/AlphaColor.vue";
import Color from "../setting/Color.vue";
import Slider from "../setting/Slider.vue";

const props = defineProps({
  config: {
    type: Object,
    required: true,
  },
  name: {
    type: String,
    default: "",
  },
  disabled: {
    type: Boolean,
    default: false,
  },
});

const emits = defineEmits(["update:config", "change"]);

const form = ref({
  $position: { left: 20, top: 20 },
  $size: { width: 335, height: 300 },
  $removeable: true,
  type: 3,
  showBgImg: false,
  bgColor: "#ffffff",
  borderRadius: 10,
  showPrizeBg: false,
  color: "#000000",
  textSize: { width: 305, height: 270 },
  textPosition: { left: 15, top: 15 },
});

const typeList = [
  { label: "一列", key: "default" },
  { label: "两列", key: 2 },
  { label: "三列", key: 3 },
  { label: "四列", key: 4 },
];

const detail = computed({
  get: () => {
    return Object.assign({}, form.value, props.config);
  },
  set: (val) => {
    emits("update:config", val);
    emits("change", val);
  },
});

const onChange = (val) => {
  detail.value = detail.value;
};

onMounted(() => {
  nextTick(() => {
    onChange();
  });
});
</script>
<template>
  <el-form :model="detail" :disabled="disabled" label-width="auto">
    <el-form-item label="布局">
      <el-radio-group v-model="config.type" @change="onChange">
        <el-radio v-for="item in typeList" :label="item.key">{{
          item.label
        }}</el-radio>
      </el-radio-group>
    </el-form-item>
    <Slider
      v-model="detail.borderRadius"
      name="圆角"
      :max="20"
      @change="onChange"
    />
    <AlphaColor v-model="config.bgColor" name="奖池背景色" @change="onChange" />
    <OImage
      v-model="config.backgroundImg"
      v-model:size="config.$size"
      v-model:show="detail.showBgImg"
      name="奖池背景图片"
      @change="onChange"
    />
    <OImage
      v-model="config.prizeBg"
      v-model:show="config.showPrizeBg"
      name="奖品背景图片"
      @change="onChange"
    />
    <AlphaColor
      v-model="config.prizeBgColor"
      name="奖品背景色"
      @change="onChange"
    />
    <Color v-model="config.color" name="文字颜色" @change="onChange" />
  </el-form>
</template>
